package com.loan.util;

import com.loan.entity.Product;

import java.math.BigDecimal;

/**
 * @ClassName: RepaymentCompute
 * @Author: wYin
 * @Date: 2022/1/18 17:42
 */
public class RepaymentCompute {
    private Product product;//选择的贷款产品
    private BigDecimal money;//贷款总额
    private BigDecimal monthlyPrincipal;//每月本金
    private BigDecimal monthlyInterest;//每月利息
    public RepaymentCompute(Product product,BigDecimal money){
        this.product = product;
        this.money = money;
    }

    /**
     * 功能描述: <br>
     * 得到每月本金
     * @Param: []
     * @Return: java.math.BigDecimal
     * @Author: wYin
     * @Date: 2022/1/18 17:49
     */
    public BigDecimal getMonthlyPrincipal() {
         this.monthlyPrincipal = money.divide(BigDecimal.valueOf(product.getTime()),2,BigDecimal.ROUND_HALF_UP);
         return monthlyPrincipal;
    }

    /**
     * 功能描述: <br>
     * 得到每月的利息
     * @Param: []
     * @Return: java.math.BigDecimal
     * @Author: wYin
     * @Date: 2022/1/18 17:50
     */
    public BigDecimal getMonthlyInterest() {
        BigDecimal rate = product.getRate();//利率
        BigDecimal totalMoney = money.multiply(rate);//总利息
        this.monthlyInterest = money.divide(BigDecimal.valueOf(product.getTime()),2,BigDecimal.ROUND_HALF_UP);
        return monthlyInterest;
    }
}